<script setup>
import { useTodosStore } from '../store';

const todos = useTodosStore()
// console.log('todos', todos.list);

todos.$subscribe(() => {
  localStorage.setItem('todos', JSON.stringify(todos.list))
})
</script>

<template>
  <section class="main">
    <input id="toggle-all" class="toggle-all" type="checkbox" :checked="todos.isCheckAll"
      @change="todos.toggleAll($event.target.checked)" />
    <label for="toggle-all">Mark all as complete</label>
    <ul class="todo-list">
      <li :class="{completed:item.done}" v-for="item in todos.filterList" :key="item.id">
        <div class="view">
          <input class="toggle" type="checkbox" :checked="item.done" @change="todos.change(item.id)" />
          <label>{{item.name}}</label>
          <button class="destroy" @click="todos.del(item.id)"></button>
        </div>
        <input class="edit" value="Create a TodoMVC template" />
      </li>
    </ul>
  </section>
</template>

<style lang="less" scoped>

</style>
